PlayerClass = class()

function PlayerClass:ctor()
    self.Mail = ""
    self.Name = "Noob"
    self.Password = ""
    self.Platform = ""
    self.Token = ""
    self.RoomID = ""
    self.Score = 0
    self.CellTypeID = nil
    self.CurrentCell = nil
    self.Tracks = {}
    self.Manors = {}

    self.RealObject = nil
    self.Parent = nil
end

function PlayerClass:CreateCharacter()
    local param = {}
    if self.Mail == EntityManager.PlayerID then
        param.ModelID = 101
    else
        param.ModelID = 102
    end

    self.Parent = Utils.FindChild(Map.ObjectParent, self.Mail)
    if LuaUtils:IsNil(parent) then
        self.Parent = GameObject.New(self.Mail)
        self.Parent.transform.parent = Map.ObjectParent.transform
        self.Parent.transform.position = Vector3.New(0, 0, 0)
    end

    param.Name = self.Name
    param.Position = Vector3.New(self.CurrentCell.x, 0, self.CurrentCell.y)
    param.Rotation = Quaternion.Euler(0, 0, 0)
    param.IsPlayer = self.Mail == EntityManager.PlayerID
    param.Parent = self.Parent

    if not LuaUtils:IsNil(self.RealObject) then
        GameObject.Destroy(self.RealObject)
    end

    self.RealObject = EntityFactory:CreateCharacter(param)
    if self.Mail == EntityManager.PlayerID then
        local inputController = self.RealObject:GetComponent(typeof(InputController))
        inputController.InputDelegate:AddCallback(self, self.InputControl)
    end
end

function PlayerClass:InputControl(Direction)
    NetworkSender:DirectionMove(Direction)
end

function PlayerClass:BindCamera()
    local camera = GameObject.Find("Camera")
    local cameraController = camera:GetComponent(typeof((CameraController)))
    camera.transform.position = self.RealObject.transform.position + Vector3.New(0, 10, -8)
    cameraController.target = self.RealObject.transform
end
